Lazy Properties

WireBox supports the concept of marking properties in your components as lazy. This will allow for the property to be constructed ONCE when requested ONLY (lazy loaded). This way you can take advantage of the construction of the property being lazy loaded.

Internally, we will generate a getter method for you that will make sure to construct your property via a builder function you will provide, lock the request (by default), store it in the variables scope and return it to you.

Note: With lazy properties, you must use the getter only to retrieve the property

component{
	
	// Lazy property: Constructed by convention via the buildUtil() method
	property name="util" lazy;

	/**
	 * Build a util object lazyily.
	 * The first time you call it, it will lock, build it, and store it by convention as 'variables.util'
	 */
	function buildUtil(){
		return new coldbox.system.core.util.Util();
	}

}

Implicit Builder

When you tag a property as lazy, we will look for method using the following pattern by convention:

function build{propertyName}(){}

We will then lock, call the builder, store the property and return it.

Explicit Builder

If you want to use ANY method in your CFC to build the property, then use the value of the lazy annotation to point to the public or private method:

component{
	
	property name="util" lazy="constructUtil";

	function constructUtil(){
		return new coldbox.system.core.util.Util();
	}

}

We will then lock, call your builder by name, store the property and return it.

No Locking

By default, WireBox will lock the construction of the property. If you do not want the locking to occur, then use the LazyNoLock attribute. Just as before, if you don’t have a value for the annotation then we will look for a build{propertyName} function or if it has a value, we will use that as the name of the builder function.

component{
	
	property name="util" lazyNoLock;
	property name="util" lazyNoLock="constructUtil";

	/**
	 * Build a util object lazyily.
	 * The first time you call it, build it, and store it by convention as 'variables.util'
	 */
	function buildUtil(){
		return new coldbox.system.core.util.Util();
	}

	function constructUtil(){
		return new coldbox.system.core.util.Util();
	}

}